home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1019 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. From: boukanov@sentef1.fi.uib.no (Igor Boukanov)
  2. Message-ID: <4ke65f$b2l@ugress.uib.no>
  3. X-Original-Date: 9 Apr 1996 17:18:39 GMT
  4. Path: in1.uu.net!bounce-back
  5. Date: 09 Apr 96 17:21:08 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Are T& and T the same from template point of view?
  9. Organization: Fysisk institutt, Universitetet i Bergen
  10. Keywords: C++, template
  11. X-Newsreader: TIN [version 1.2 PL2]
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMWqci+EDnX0m9pzZAQFAnwF8CAIn75RsOb04yvvFnRmpGpasxz95ZxyN
  14.     o7Fbpal3n3RyUtDtGDvtwXpkymWtp7xj
  15.     =Sy5N
  16.  
  17. Consider the following code example:
  18. #include<iostream.h>
  19. template<class T> void incr(T t) { ++t; }
  20. typedef int& rint;
  21. void main() {
  22.    int i = 0;
  23.    incr(rint(i));  // Atemption to use 'template void incr<rint>(rint)'
  24.    cout << i << '\n';
  25. }
  26.  
  27. I compiled it by g++ 2.7.2 and the program printed 0. Is this right from 
  28. the standard point of view and call 'incr((int&)i)' should always use 
  29. 'template void incr<int>(int)' instead of 'template void incr<int&>(int&)' ?
  30.  
  31. --
  32. Regards, Igor Boukanov. 
  33. igor.boukanov@fi.uib.no  
  34. http://www.fi.uib.no/~boukanov/
  35. ---
  36. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  37. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  38. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  39. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  40. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  41.